package com.crm.service.impl.couponManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.couponManager.CustomerContractCouponMapper;
import com.crm.dao.mapper.customMapper.couponCustomManager.CustomerContractCouponCustomMapper;
import com.crm.model.entity.couponManager.CustomerContractCoupon;
import com.crm.model.entity.couponManager.CustomerContractCouponExample;
import com.crm.model.vo.couponManager.CouponPayListVO;
import com.crm.service.couponManager.ContractCouponDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luojie
 * @date 2021/5/21 15:54
 */
@Service
public class ContractCouponDbServiceImpl implements ContractCouponDbService {

    @Autowired
    private CustomerContractCouponMapper customerContractCouponMapper;
    @Autowired
    private CustomerContractCouponCustomMapper customerContractCouponCustomMapper;

    /***
     * @Description:插入合同优惠券表
     * @Param:customerContractCoupon 参数
     * @Author: luojie
     * @Date: 2021/5/21 15:53
     */
    @Override
    public Boolean insertCustomerCoupon(CustomerContractCoupon customerContractCoupon) {
        int num = customerContractCouponMapper.insertSelective(customerContractCoupon);
        return num>0;
    }

    /***
     * @Description:根据合同id查询合同优惠券信息
     * @Param:contractId 合同id
     * @Author: luojie
     * @Date: 2021/5/21 16:11
     */
    @Override
    public List<CustomerContractCoupon> selectContractCouponByContractId(String contractId) {
        CustomerContractCouponExample customerContractCouponExample = new CustomerContractCouponExample();
        CustomerContractCouponExample.Criteria criteria = customerContractCouponExample.createCriteria();
        criteria.andContractIdEqualTo(contractId);
        criteria.andDeleteStatusEqualTo((short) StatusCodeEnum.NORMAL_CODE.getState());
        List<CustomerContractCoupon> customerContractCouponList = customerContractCouponMapper.selectByExample(customerContractCouponExample);
        return customerContractCouponList;
    }

    /**
     * 根据优惠券id及客户id查看该客户的该优惠券的使用记录
     * @Author renshaorong
     * @Date 2021/11/30
     * @param couponId
     * @param customerId
     * @return
     */
    @Override
    public List<CouponPayListVO> selectContractCouponByCouponIdAndCustomerId(String couponId, String customerId){
        return customerContractCouponCustomMapper.selectContractCouponByCouponIdAndCustomerId(couponId,customerId);
    }
}
